<template>
	<view class="bg-white">
		<view class="padding-sm">
			<u-form :model="form" ref="uForm">
				<u-form-item label="姓名" prop="name" :label-position="labelPosition" :label-style="labelStyle"
					style="color: #000000;font-weight: bold;font-size: 4rpx;line-height: 26rpx;">
					<u-input :border="border" v-model="form.name" placeholder="请输入您真实姓名" />
				</u-form-item>				
				<u-form-item label="手机号码" prop="mobile" :label-position="labelPosition"
					style="color: #000000;font-weight: bold;font-size: 48rpx;">
					<u-input :border="border" type="tel" v-model="form.mobile" placeholder="请输入您真实手机号码" />
				</u-form-item>
				<u-form-item label="电子邮箱" prop="email" :label-position="labelPosition"
					style="color: #000000;font-weight: bold;font-size: 48rpx;">
					<u-input :border="border" v-model="form.email" placeholder="请输入您电子邮箱（选填）" />
				</u-form-item>				
			</u-form>
			<view class="">
				<button class="cu-btn block bg-blue margin-tb-sm lg" type="" @click="update">保存更新</button>
			</view>
		</view>
	</view>
</template>

<script>
	var that
	export default {
		data() {
			return {
				form: {
					name: '',
					card: '',
					mobile: '',
					email: '',
					salesman_name: '',
					salesman_mobile: '',
					company: []
				},
				agreement:false,
				labelPosition: 'top',
				border: false,
				labelStyle: {
					'line-height': '26rpx'
				},
				rules: {
					name: [{
						validator: (rule, value, callback) => {
							return this.$u.test.chinese(value);
						},
						message: '姓名不正确',
						trigger: ['change', 'blur'],
					}],
					card: [{
						validator: (rule, value, callback) => {
							return this.$u.test.idCard(value);
						},
						message: '身份证号不正确',
						trigger: ['change', 'blur'],
					}],
					mobile: [{
						validator: (rule, value, callback) => {
							return this.$u.test.mobile(value);
						},
						message: '手机号不正确',
						trigger: ['change', 'blur'],
					}]
				},
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		created() {
			that = this
			that.$u.post('index/member').then(res => {
				that.form = res
			})
		},
		methods: {
			open(e){
				wx.downloadFile({
				  // 示例 url，并非真实存在
				  url: 'https://wx.qdhansen.com/' + e + '.pdf',
				  success: function (res) {
				    const filePath = res.tempFilePath
				    wx.openDocument({
				      filePath: filePath,
				      success: function (res) {
				        console.log('打开文档成功')
				      }
				    })
				  }
				})
			},
			companyChange(e){
				that.form.company = e
			},
			xiankankan(){
				uni.switchTab({
					url:'/pages/index/index',
					success() {
						uni.setStorageSync('islogin', 1);
					}
				})				
			},
			update() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						let param = {
							'name':that.form.name,
							'mobile':that.form.mobile,
							'email':that.form.email,
							'openid':that.form.openid,
							'id':that.form.id,
							'salesman_name':that.form.salesman_name,
							'salesman_mobile':that.form.salesman_mobile,
						}
						that.$u.post('index/update', param).then(res => {
							if (res.code == 300) {
								uni.showToast({
								    title: res.msg,
								    duration: 2000,
										icon:"none"
								});
								return false
							}
							uni.switchTab({
								url:'../index/index'
							})
						})
					} else {
						console.log('验证失败');
					}
				});
				
			}
		}
	}
</script>

<style scoped lang="scss">
	.agreement {
		display: flex;
		align-items: center;
		margin: 40rpx 0;

		.agreement-text {
			padding-left: 8rpx;
			color: $u-tips-color;
		}
	}
</style>
